﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HandyControl.Collections;
using HandyControl.Controls;
using static System.Net.Mime.MediaTypeNames;

namespace weighing
{
    /// <summary>
    /// ReportPopupWin.xaml 统计详细信息 的交互逻辑
    /// </summary>
    public partial class ReportPopupWin : GlowWindow
    {
        private static string unitText = App.Config.WeighingConfig.Unit == Unit.Tone ? "吨" : "千克";
        private string ListBoxItemLabelTemplate = " 公司名称：{0}  物资名称：{1}  {2}(车)  毛重：{3}  皮重： {4}  净重：{5} (" + unitText + ")";


        private List<ReportWeightListV> DetailList = new List<ReportWeightListV>();

        private string sumaryTitle = "";

        public ReportPopupWin(List<ReportWeightListV> detailList, string title)
        {
            InitializeComponent();

            CommonFunction.ShowCustomIcon(this);

            this.DetailList = detailList;
            this.sumaryTitle = title;
        }

        private void GlowWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (DetailList == null || DetailList.Count <= 0)
            {
                this.Close();
            }

        }

        private void GlowWindow_ContentRendered(object sender, EventArgs e)
        {
            this.summaryTextBlock.Text = sumaryTitle;
            StringBuilder sb = new StringBuilder();
            foreach (ReportWeightListV v in DetailList)
            {             
                var t = String.Format(this.ListBoxItemLabelTemplate, v.Company, v.Material, v.Cars, v.GrossWeight, v.TraeWeight, v.Weight);
                sb.AppendLine(t);

            }
            this.statisticListBox.Text = sb.ToString();
        }

        private void GlowWindow_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if(e.Key == Key.Escape) this.Close();
        }
    }
}
